String clazzTpl({package}) => """
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:$package/utils/print_util.dart';
import 'package:$package/utils/toast_util.dart';

/// Generates Dart code
class ResponseInterceptors extends InterceptorsWrapper {
  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) async {
    try {
      if (response.statusCode == 200) {
        // Toast.showSucc(succMsg);
      }
    } catch (e) {
      logDebugPrint(e.toString());
    }
    handler.next(response);
  }

  @override
  void onError(DioError err, ErrorInterceptorHandler handler) async {
    try {
      var statusCode = err.response?.statusCode ?? 500;

      final errMsg = _dioError(err);
      if (statusCode >= 500) {
        // Toast.showFail(errMsg);
      } else if (statusCode >= 400) {
        // Toast.showWarn(warnMsg);
      } else {
        Toast.showFail(errMsg);
      }
    } catch (e) {
      if (kDebugMode) {
        print("ResponseInterceptors onError error: \$e");
      }
    }
    handler.next(err);
  }

  String _dioError(DioError error) {
    switch (error.type) {
      case DioErrorType.connectionTimeout:
        return "网络连接超时，请检查网络设置";
      case DioErrorType.sendTimeout:
        return "网络发送超时，请检查网络设置";
      case DioErrorType.receiveTimeout:
        return "网络响应超时，请稍后重试";
      case DioErrorType.badCertificate:
        return "网络证书异常，请稍后重试";
      case DioErrorType.cancel:
        return "请求被取消，请稍后重试！";
      case DioErrorType.connectionError:
        return "网络异常，请稍后重试！";
      case DioErrorType.badResponse:
      case DioErrorType.unknown:
        try {
          return error.response?.data["message"] ?? '网络异常，请稍后重试！';
        } catch (e) {
          return '网络异常，请稍后重试！';
        }
      default:
        return "网络未知异常，请稍后重试！";
    }
  }
}
""";
